<?php
if(!defined('IN_ORA')) {
	exit('Access Denied');
}
class art extends mod{

	function __construct(){
		parent::__construct();
	}
	/*** 查看新闻 ***/
	function v(){
		$id = intval($GLOBALS['_param']['id']);
		if(!$this->isCached("art-v-id_$id")){
			/** 站点信息 **/
			$this->assign('sinfo',$GLOBALS['db']->getOne('select * from '.tn('info').' order by Id asc limit 1'));

			/** 导航信息 **/
			$this->assign('navs',$GLOBALS['db']->getAll('select * from '.tn('nav').' order by nav_sort desc'));

			/** 新闻分类 **/
			import("lib.cat");
			$this->assign('cates',cat_lib::getSubChild(0,2,' and cat_type=0'));

			$sql = "select oa.*,oc.cat_name,oc.path,octont.content from ".tn('article')." oa ";
			$sql.= "left join ".tn('cat')." oc on oa.cat_id = oc.Id ";
			$sql.= "left join ".tn('content')." octont on octont.fk_id = oa.Id ";
			$sql.= " where octont.ctype = 0 and oa.id= $id and oa.status > 0 order by oa.status desc";
			$art = $GLOBALS['db']->getOne($sql);
			if(!$art){
				redirect("index-index|true");
			}
			if($art['tags']){
				$art['tags'] = explode(",",$art['tags']);
			}
			$art['next'] = $this->db->getOne("select * from ".tn('article')." where Id > ".$art['Id']." order by Id asc  limit 1");
			$art['prev'] = $this->db->getOne("select * from ".tn('article')." where Id < ".$art['Id']." order by Id desc  limit 1");
			$this->assign('art',$art);

			/** 专题标签 **/
			$this->assign('tags',$GLOBALS['db']->getAll('select * from '.tn('tags').' where tag_type=0 group by tag_name order by Id desc'));
			/** 当前位置 **/
			$local = array();
			$local[] = array('url'=>parse_uri('art-index'),'text'=>'资讯');
			$q = $GLOBALS['db']->query("select Id,cat_name from ".tn('cat')." where id in(".str_replace('-',',',$art['path']).")");
			while ($row=$GLOBALS['db']->fetch_array($q)) {
				$local[] = array('url'=>parse_uri('art-cat-id-%d',$row['Id']),'text'=>$row['cat_name']);
			}
			$local[] = array('url'=>parse_uri('art-cat-id-%d',$art['cat_id']),'text'=>$art['cat_name']);
			$local[] = array('url'=>parse_uri('art-v-id-%d',$art['Id']),'text'=>$art['title']);
			$this->assign('local',$local);
			$this->assign('title',array_reverse($local));
			unset($art);
		}
		/** 浏览计数 **/
		if(!isset($_COOKIE["views"]["art-$id"])){
			$GLOBALS['db']->execute("update ".tn('article')." set views = views + 1");
			setcookie("views[art-$id]", "ora",time()+3600);
		}
		$this->assign('views',$GLOBALS['db']->count("select views from ".tn('article')." where Id = $id"));

		$this->display("art.html");
	}

	function index(){
		$this->cat();
	}
	/** 动态分类 **/
	function cat(){
		$id = intval($GLOBALS['_param']['id']);
		$pid= intval($GLOBALS['_param']['p']);
		$pid= $pid>0?$pid:1;
		import("lib.page");
		if(!$this->isCached("art-cat-id-$id-pid-$pid")){
			/** 站点信息 **/
			$this->assign('sinfo',$GLOBALS['db']->getOne('select * from '.tn('info').' order by Id asc limit 1'));

			/** 导航信息 **/
			$this->assign('navs',$GLOBALS['db']->getAll('select * from '.tn('nav').' order by nav_sort desc'));

			/** 新闻分类 **/
			import("lib.cat");
			$cates = cat_lib::getSubChild(0,2,' and cat_type=0');
			$this->assign('cates',$cates);
			$this->assign('curr_cat_id',$id);

			/** 专题标签 **/
			$this->assign('tags',$GLOBALS['db']->getAll('select * from '.tn('tags').' where tag_type=0 group by tag_name order by Id desc'));

			$curr_cat = $GLOBALS['db']->getOne("select * from ".tn('cat')." where id = $id");
			if($curr_cat){
				$this->assign('curr_cat',$curr_cat);
			}
			$psize = $GLOBALS['_param']['psize']?$GLOBALS['_param']['psize']:$GLOBALS['ora_cfg']['page_size'];
			$idStr = cat_lib::getCatIdStr($id);
			$total = $GLOBALS['db']->count("select count(*) from ".tn('article')." where status > 0 and cat_id in ($idStr) ");

			$pobj = new page('p',$pid,$total,$psize);
			$sql = "select oa.*,oc.cat_name from  ".tn("article")." oa inner join ( select Id from  ".tn("article");
			$sql .= " where cat_id in (".$idStr.") and status > 0 order by status desc limit ".$pobj->sqlParam.") b using(Id) left join ".tn("cat")." oc on oa.cat_id = oc.Id ";
			if($pobj->rsort){
				$sql = "select oa.*,oc.cat_name from  ".tn("article")." oa inner join ( select Id from  ".tn("article");
				$sql .= " where cat_id in (".$idStr.") and status > 0 order by status asc limit ".$pobj->sqlParam.") b using(Id) left join ".tn("cat")." oc on oa.cat_id = oc.Id";
			}
			$this->assign("pobj",$pobj);
			$url = get_urlStr();
			$this->assign('url',preg_replace('/\-?p(\-|_)\d+/i',"",$url));
			$arts = $this->db->getAll($sql);
			/** 提取分类下第一个产品的详细信息作为分类SEO描述头信息 **/
			if($arts[0]){
				$content = $this->db->getOne("select content from ".tn('content')." where ctype=0 and fk_id = ".$arts[0]['Id']);
				if($content){
					$arts[0]['desc'] = htmlspecialchars(msubstr($content['content'],0,150));
				}
			}

			$this->assign('arts',$arts);
			/** 当前位置 **/
			$local = array();
			$local[] = array('url'=>parse_uri('art-index'),'text'=>'资讯');
			if($curr_cat){
				$q = $GLOBALS['db']->query("select Id,cat_name from ".tn('cat')." where id in(".str_replace('-',',',$curr_cat['path']).")",true);
				while (@$row=$GLOBALS['db']->fetch_array($q)) {
					$local[] = array('url'=>parse_uri('art-cat-id-%d',$row['Id']),'text'=>$row['cat_name']);
				}
				$local[] = array('url'=>parse_uri('art-cat-id-%d',$curr_cat['Id']),'text'=>$curr_cat['cat_name']);
			}
			$this->assign('local',$local);
			$this->assign('title',array_reverse($local));
		}
		$this->display("art_cat.html");
	}
}
?>